import {action, observable, runInAction} from "mobx";
import {BaseResInterface, BaseResInterfaceWithData, sendGetRequest} from "../../../net";
import {UserRealInfoInterface, UserVipInfoInterface} from "../../../net/instance/CommenModelInstance";
import {defaultObj} from "../../../util";
import UserStoreInstance from "./index";


interface UserRealInfoRes {
    realInfo: UserRealInfoInterface
}

export class RealInfoStore {
    @observable userVipInfo: UserVipInfoInterface = defaultObj;
    @observable userRealInfo: UserRealInfoRes = defaultObj;

    @action.bound
    async getUserVipInfo() {
        const {data} = await sendGetRequest<BaseResInterfaceWithData<UserVipInfoInterface>>("user/getUserVipInfo", {
            id: UserStoreInstance.user.id
        });
        console.log("=====");
        console.log(data);
        console.log("=====");

        runInAction(() => {
            this.userVipInfo = data;
        });
    }

    @action.bound
    async getUserRealInfo() {
        const {data} = await sendGetRequest<BaseResInterfaceWithData<UserRealInfoRes>>("user/getUserRealInfo", {userId: UserStoreInstance.user.id});
        runInAction(() => {
            this.userRealInfo = data;
        })
    }
}

const RealInfoStoreInstance = new RealInfoStore();
export default RealInfoStoreInstance